//左侧导航
$(document).ready(function(){
    $('#menu').tendina({
        openCallback: function(clickedEl) {
            clickedEl.addClass('opened');
        },
        closeCallback: function(clickedEl) {
            clickedEl.addClass('closed');
        }
    });

});
$(function(){

    $("#ad_setting").click(function(){
        $("#ad_setting_ul").show();
    });
    $("#ad_setting_ul").mouseleave(function(){
        $(this).hide();
    });
    $("#ad_setting_ul li").mouseenter(function(){
        $(this).find("a").attr("class","ad_setting_ul_li_a");
    });
    $("#ad_setting_ul li").mouseleave(function(){
        $(this).find("a").attr("class","");
    });
});
function randomString(len) {
　　len = len || 32;
　　var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
　　var maxPos = $chars.length;
　　var pwd = '';
　　for (i = 0; i < len; i++) {
　　　　pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
　　}
　　return pwd;
}
//投票增加
$(document).ready(function(){
    //单行填空题增加
    n = 1;
    n1 = 1;
    n2 = 2;
    m = 1;
    s = 1;
    $("#addText").click(function(){
        var voterad=randomString(7);
        var div="<div id='"+voterad+"'>"
            +"<label class=\"col-md-12\">"
            +"<span id=\"vote-tit\">"
            +"单行填空题</span>"
            +"<span class=\"icon-remove vo-remove\">"
            +"</span>"
            +"</label>"
            +"<div class=\"col-md-8\">"
            +"<div class=\"input-group input-group-lg\">"
            +"<span class=\"input-group-addon\">"
            +"题目名</span>"
            +"<input name=q0"+n+" class=\"form-control\" placeholder=\"请在此输入该题的问题\">"
            +"</div>"
            +"<div class=\"col-md-12 vote-line\">"
            +"<input class=\"form-control\" placeholder=\"此处无需填写\" readonly=\"readonly\">"
            +"</div></div>";
　  　  $("#ap-form").append(div);
        $(".vo-remove").click(function(){
            var raid=$(this).closest("div")[0].id;
            var raid="#"+raid;
            $(raid).remove();
        });
        n = n+1;　
    });
    //单选题增加
    $("#addRadio").click(function(){
        var votenum=randomString(7);
        var voteopt=randomString(7);
        var addRnewid="addnew"+voteopt;
        var div="<div id='"+votenum+"'>"
            +"<label class=\"col-md-8\">"
            +"<span id=\"vote-tit\">"
            +"单选题</span>"
            +"<span class=\"icon-remove vo-remove\" name=\"vo-remove\">"
            +"</span>"
            +"</label>"
            +"<div class=\"col-md-8\">"
            +"<div class=\"input-group input-group-lg\">"
            +"<span class=\"input-group-addon\">"
            +"题目名</span>"
            +"<input name=q1"+n+" class=\"form-control\" placeholder=\"请在此输入该题的问题\">"
            +"</div>"
            +"<div id='"+voteopt+"' class=\"col-md-12 vote-line\">"
            +"<div class=\"radio\">"
            +"<label><input type=\"radio\" name=\"optionsRadios\" id=\"optionsRadios1\">"
            +"<input name='a"+n+n1+"' type=\"text\" placeholder=\"选项\" />"
            +"<span class=\"icon-remove option-remove\">"
            +"</span>"
            +"</label>"
            +"</div>"
            +"<div class=\"radio\">"
            +"<label><input type=\"radio\" name=\"optionsRadios\" id=\"optionsRadios1\">"
            +"<input name='a"+n+n2+"' name=q1"+n+" type=\"text\" placeholder=\"选项\" />"
            +"<span class=\"icon-remove option-remove\">"
            +"</span>"
            +"</label>"
            +"</div>"
            +"</div>"
            +"<span class=\"icon-plus-sign addnew\" id='"+addRnewid+"'>"
            +"增加该题选项</span>"
            +"</div>";  
　  　  $("#ap-form").append(div);
        //新增
        var addRnewid="#"+addRnewid;
        $(addRnewid).click(function(){
            n2 = n2 + 1;
            var addRnewid="<div class=\"radio\">"
            +"<label><input type=\"radio\" name=\"optionsRadios\" id=\"optionsRadios1\" value=\"option1\">"
            +"<input name='a"+n+n2+"' type=\"text\" placeholder=\"选项\" />"
            +"<span class=\"icon-remove option-remove\">"
            +"</span>"
            +"</label>"
            +"</div>";
            // console.log(addRnewid);
            var bid=$(this).prev().attr("id");
            var bid="#"+bid;
            $(bid).append(addRnewid);
            //删除选项
            $(".option-remove").click(function(){
                $(this).parents("label").remove();
            });
        });
        //删除此题
        $(".vo-remove").click(function(){
            var fid=$(this).closest("div")[0].id;
            var rid="#"+fid;
            $(rid).remove();
        });
        n = n+1;
        m = m+1;
    });
    //多选题增加
    $("#addCheckbox").click(function(){
        var votechex=randomString(7);
        var votechexop=randomString(7);
        var addCnewid="addnew"+votechexop;
        var div="<div id='"+votechex+"'>"
            +"<label class=\"col-md-8\">"
            +"<span id=\"vote-tit\">"
            +"多选题</span>"
            +"<span class=\"icon-remove vo-remove\" name=\"vo-remove\">"
            +"</span>"
            +"</label>"
            +"<div class=\"col-md-8\">"
            +"<div class=\"input-group input-group-lg\">"
            +"<span class=\"input-group-addon\">"
            +"题目名</span>"
            +"<input name=qn"+n+" class=\"form-control\" placeholder=\"请在此输入该题的问题\">"
            +"</div>"
            +"<div class=\"input-group limi-op\">"
            +"<span>最多选</span>"
            +"<input name=qn"+n+n+" type=\"text\" style=\"width:20%\"/>项"
            +"</div>"
            +"<div id='"+votechexop+"' class=\"col-md-12 vote-line\">"
            +"<div class=\"radio\">"
            +"<label><input type=\"checkbox\">"
            +"<input type=\"text\" placeholder=\"选项\" />"
            +"<span class=\"icon-remove option-remove\">"
            +"</span>"
            +"</label>"
            +"</div>"
            +"<div class=\"radio\">"
            +"<label><input type=\"checkbox\">"
            +"<input type=\"text\" placeholder=\"选项\" />"
            +"<span class=\"icon-remove option-remove\">"
            +"</span>"
            +"</label>"
            +"</div>"
            +"</div>"
            +"<span class=\"icon-plus-sign addnew\" id='"+addCnewid+"'>"
            +"增加该题选项</span>"
            +"</div>";  
　  　  $("#ap-form").append(div);
        //新增
        var addCnewid="#"+addCnewid;
        $(addCnewid).click(function(){
            var input="<div class=\"radio\">"
            +"<label><input type=\"checkbox\">"
            +"<input type=\"text\" placeholder=\"选项\" />"
            +"<span class=\"icon-remove option-remove\">"
            +"</span>"
            +"</label>"
            +"</div>";
            var bid=$(this).prev().attr("id");
            var bid="#"+bid;
            // console.log(bid);
            $(bid).append(input);
            //删除选项
            $(".option-remove").click(function(){
                $(this).parents("label").remove();
            });
        });
        //删除
        $(".vo-remove").click(function(){
            var fid=$(this).closest("div")[0].id;
            var rid="#"+fid;
            // console.log(rid);
            $(rid).remove();
        });
        n = n+1;
        m = m+1;
        s = s+1;
    });
    //单图增加

});
$('form').submit(function(){ 
    alert($(this).serialize()); 
    returnfalse; 
});
